package com.example.myapplication.model.mention;

import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;


public class MentionUser implements IntegratedSpan, BreakableSpan, DataSpan{
    private int locaction;
    private String nickname;
    private String Uid;

    public long id;
    private Object styleSpan;

    public MentionUser(String name,String Uid) {
        this.nickname = name;
        this.Uid = Uid;
        id = System.currentTimeMillis();
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public int getLocaction() {
        return locaction;
    }

    public void setLocaction(int locaction) {
        this.locaction = locaction;
    }

    public String getUid() {
        return Uid;
    }

    public void setUid(String uid) {
        Uid = uid;
    }

    public Spannable getSpanableString() {
        styleSpan = new ForegroundColorSpan(Color.parseColor("#127EE0"));
        SpannableString spannableString = new SpannableString(getDisplayText());
        spannableString.setSpan(styleSpan, 0, spannableString.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(this, 0, spannableString.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
        return stringBuilder.append(spannableString);
    }

    private CharSequence getDisplayText() {
        return "@" + nickname;
    }



    @Override
    public boolean isBreak(Spannable text) {
        int spanStart = text.getSpanStart(this);
        int spanEnd = text.getSpanEnd(this);
        boolean isBreak = spanStart >= 0 && spanEnd >= 0 && !text.subSequence(spanStart, spanEnd).toString().equals(
                getDisplayText());
        if (isBreak && styleSpan != null) {
            text.removeSpan(styleSpan);
            styleSpan = null;
        }
        return isBreak;
    }
}
